package cz.semjob.framework;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cz.semjob.document.annotation.LabeledRelationWordsPair;
import cz.semjob.document.annotation.LabeledWords;
import cz.semjob.document.processing.DocumentInstance;
import cz.semjob.document.util.DocumentUtil;
import cz.semjob.output.data.ClassificationInfo;

public class DocumentAnnotationResults {

	private DocumentInstance documentInstance;

	private Map<String, ClassificationInfo> classifierInfoMap;

	private List<LabeledWords> labeledWords;
	private List<LabeledWords> labeledWordsWithDuplicates;
	private List<LabeledRelationWordsPair> labeledRelations;

	public DocumentAnnotationResults(DocumentInstance documentInstance) {
		super();
		this.documentInstance = documentInstance;
		this.labeledWords = new ArrayList<LabeledWords>();
		this.labeledWordsWithDuplicates = new ArrayList<LabeledWords>();
		this.labeledRelations = new ArrayList<LabeledRelationWordsPair>();
		this.classifierInfoMap = new HashMap<String, ClassificationInfo>();
	}

	public void addClassifierInfo(String classifierName,
			ClassificationInfo classificationInfo) {
		this.classifierInfoMap.put(classifierName, classificationInfo);
	}

	public void addConceptAnnotations(Collection<LabeledWords> annotations) {
		this.labeledWordsWithDuplicates.addAll(annotations);
		annotations = DocumentUtil.removeDuplicates(annotations);
		this.labeledWords.addAll(annotations);
	}

	public void addRelationsAnnotations(
			Collection<LabeledRelationWordsPair> annotations) {
		this.labeledRelations.addAll(annotations);
	}

	public DocumentInstance getDocumentInstance() {
		return documentInstance;
	}

	public List<LabeledWords> getLabeledWords() {
		return labeledWords;
	}

	public List<LabeledRelationWordsPair> getLabeledRelations() {
		return labeledRelations;
	}
	

	public List<LabeledWords> getLabeledWordsWithDuplicates() {
		return labeledWordsWithDuplicates;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder(
				"DocumentAnnotationResults(documentInstance="
						+ documentInstance.getFileName() + ")\n");
		sb.append("Concepts:\n");
		for (LabeledWords words : labeledWords) {
			sb.append(DocumentUtil.printConcept(words) + "\n");

		}
		sb.append("Relations:\n");
		for (LabeledRelationWordsPair relationWordsPair : labeledRelations) {
			sb.append(DocumentUtil.printLabeledRelation(relationWordsPair)
					+ "\n");

		}
		return sb.toString();
	}

	public Map<String, ClassificationInfo> getClassifierInfoMap() {
		return classifierInfoMap;
	}

	public String printCounts() {
		return documentInstance.getFileName() + " (Concepts: "
				+ labeledWords.size() + " Relations: "
				+ labeledRelations.size() + ")";
	}

}
